package com.heeexy.example.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.dao.ClientDao;
import com.heeexy.example.service.ClientService;
import com.heeexy.example.util.CommonUtil;
import com.heeexy.example.util.constants.ErrorEnum;


@Service
public class ClientServiceImpl implements ClientService {

	@Autowired
	private ClientDao clientDao;
	
	@Override
	public JSONObject addClient(JSONObject jsonObject) {
		clientDao.insertClient(jsonObject);
		return CommonUtil.successJson();
	}

	@Override
	public JSONObject listClient(JSONObject jsonObject) {
		CommonUtil.fillPageParam(jsonObject);
        int count = clientDao.countClient(jsonObject);
        List<JSONObject> list =  clientDao.listClient(jsonObject);
        return CommonUtil.successPage(jsonObject, list, count);
	}

	@Override
	@SuppressWarnings("unchecked")
	public JSONObject updateClient(JSONObject jsonObject) {
		clientDao.updateClient(jsonObject);
		return CommonUtil.successJson();
	}
	
	
	//@Transactional(rollbackFor = Exception.class)
	//@SuppressWarnings("unchecked")
	@Override
	public JSONObject deleteClient(JSONObject jsonObject) {
		clientDao.deleteClient(jsonObject);
		return CommonUtil.successJson();
	}

	@Override
	public JSONObject getAllClient() {
		// TODO Auto-generated method stub
		return null;
	}

	



}
